<template>
	<view>
		<template v-if="list.length>0">
		<block v-for="(item,idx) in list" :key="idx">
			<index-list :item="item"></index-list>
		</block>
		<!-- 上拉加载 -->					
		<load-more :loadtext="loadtext"></load-more>
		</template>
		<template v-if="issearch && list.length<1">
			<no-thing></no-thing>
		</template>
	</view>
</template>

<script>
	import indexList from '../../components/index/index-list.vue'
	import loadMore from '../../components/common/load-more.vue';
	import noThing from '../../components/common/no-thing.vue';
	export default {
		components:{
			indexList,
			loadMore,
			noThing
		},
		data() {
			return {
				issearch: false,
				loadtext: "上拉加载更多",
				list: []
				
			}
		},
		onNavigationBarButtonTap(e){
			if(e.index === 0){
				uni.navigateBack({
					delta: 1
				})
			}
		},
		//输入事件
		onNavigationBarSearchInputChanged(e){   
			console.log(e.text)
		},
		//搜索回车按钮触发事件
		onNavigationBarSearchInputConfirmed(e){
			if(e.text){
				this.getdata(e.text)
			}
		},
		//使用scroll-view的下拉触底方法无效时 使用这个原生
		onReachBottom(){
			this.loadmore()		
		},
		//使用下拉刷新
		onPullDownRefresh(){
			console.log(1)
			uni.startPullDownRefresh()
			this.getdata()
			uni.stopPullDownRefresh()
		},
		methods: {
			getdata(keyword){
				//关键词请求数据
				uni.showLoading()
				setTimeout(()=>{
					let arr= [
					{
						userpic: "../../static/demo/userpic/12.jpg",
						username: "昵称",
						isguanzhu: false,
						title: "大大的标题",
						type: "img", 	// img|video
						titlepic: "../../static/demo/datapic/11.jpg",
						playnum: '20w',
						playtime: '2:47',
						infonum: {
							status: 0,	// 0-没有操作，1-顶，2-踩
							dingnum: 11,
							cainum: 11
						},
						commentnum: 10,
						sharenum: 10,
					},
					{
						userpic: "../../static/demo/userpic/12.jpg",
						username: "昵称",
						isguanzhu: true,
						title: "大大的标题",
						type: "video", 	// img|video
						titlepic: "../../static/demo/datapic/11.jpg",
						playnum: '20w',
						playtime: '2:47',
						infonum: {
							status: 2,	// 0-没有操作，1-顶，2-踩
							dingnum: 12,
							cainum: 11
						},
						commentnum: 10,
						sharenum: 10,
					}
				]
				if(keyword == 1){					
					this.list = arr;
					this.loadtext = "上拉加载更多";
				}else{
					this.list = []
				}
					uni.hideLoading()
					this.issearch = true;
				},1000);
			},
			loadmore(){
				if(this.loadtext != "上拉加载更多") return;
				this.loadtext = "加载中...";
				setTimeout(()=>{
					let obj ={
								userpic: "../../static/demo/userpic/12.jpg",
								username: "昵称",
								isguanzhu: false,
								title: "大大的标题",
								type: "img", 	// img|video
								titlepic: "../../static/demo/datapic/11.jpg",
								playnum: '20w',
								playtime: '2:47',
								infonum: {
									status: 0,	// 0-没有操作，1-顶，2-踩
									dingnum: 11,
									cainum: 11
								},
								commentnum: 10,
								sharenum: 10,
							}
					this.list.push(obj);
					this.loadtext = "上拉加载更多";
				},500);
				
			}
		}
	}
</script>

<style>

</style>
